package org.stars.config;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.stars.message.Message;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 沧月
 * @date 2020/10/28
 * @desc 全局异常捕获
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Message<String> globalException(HttpServletRequest request, Exception ex) {
        String errorMessage = ex.getMessage();//错误信息
        return new Message<String>().setMsg(errorMessage).setCode(500);
    }
}
